﻿using AutoMapper;
using HamcoWcs.Contract.ContractCommon;
using HamcoWcs.DAL;
using HamcoWcs.Service.Common;
using Microsoft.Extensions.Configuration;
using Quartz;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

namespace HamcoWcs.Workers
{
    /// <summary>显示屏数据服务</summary>
    [DisallowConcurrentExecution]
    public class TibcoMonitorWorker : WorkerBase
    {
        public override Task Execute(IJobExecutionContext context)
        {

#if DEBUG
            return Task.CompletedTask;
#endif
            var tibcoRootPath = _configuration["TibcoRootPath"];
            if (string.IsNullOrEmpty(tibcoRootPath))
            {
                return Task.CompletedTask;
            }

            var tibcoProcessName = "HamcoWcs.Tools.Tibco.exe";

            var progress = Process.GetProcessesByName("HamcoWcs.Tools.Tibco");

            if (progress.Length == 0)
            {
                var fileName = Path.Combine(tibcoRootPath, tibcoProcessName);
                var cmd = $"start {fileName}";
                CmdHelper.ExcuteCommand(cmd, tibcoRootPath);
            }

            return Task.CompletedTask;
        }


        private readonly IConfiguration _configuration;


        public TibcoMonitorWorker(IConfiguration configuration, WcsDbContext wcsDbContext, IMapper mapper, ILoggerService logger) : base(wcsDbContext, mapper, logger)
        {
            _configuration = configuration;
        }
    }
}
